package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;



import sjtu.ist.warehouse4ws.model.Permission;

import sjtu.ist.warehouse4ws.service.PermissionService;
import sjtu.ist.warehouse4ws.service.RolepermissionsService;


import com.opensymphony.xwork2.ActionSupport;

public class ShowPermissionAction extends ActionSupport{
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 7797460115963418903L;
	private List<Permission> permissionList=new ArrayList<Permission>();
    private PermissionService permissionService;
    private String permissionid;
    private String roleid;
    private RolepermissionsService rolepermissionsService;
    

	public String getPermissionid() {
		return permissionid;
	}
	public void setPermissionid(String permissionid) {
		this.permissionid = permissionid;
	}
	public String getRoleid() {
		return roleid;
	}
	public void setRoleid(String roleid) {
		this.roleid = roleid;
	}
	
	
	public RolepermissionsService getRolepermissionsService() {
		return rolepermissionsService;
	}
	public void setRolepermissionsService(
			RolepermissionsService rolepermissionsService) {
		this.rolepermissionsService = rolepermissionsService;
	}
	public PermissionService getPermissionService() {
		return permissionService;
	}
	public void setPermissionService(PermissionService permissionService) {
		this.permissionService = permissionService;
	}
	
	public String showPermission(){
		
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.roleid=request.getParameter("cid");
		System.out.print(this.roleid);
		List <String> permissionids=rolepermissionsService.getPermissionsByRoleid(roleid);
	
		
		for(String a : permissionids){
			System.out.println(permissionService.getPermissionById(a));
			System.out.println("permission!!!!!!!!!");
			this.permissionList.addAll(permissionService.getPermissionById(a));
		}

		System.out.println(permissionList.size());
	    
	  
	  		return SUCCESS;										//获取得到的数据
		
		}
	@JSON(name = "totalPermission")	
	public int getTotalAttribute() {
		return this.permissionList.size();
	}
    
	
	@JSON(name ="permission")	
	public List<Permission> getPermissionList() {
		return this.permissionList;
	}
    
}
